<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" class="tl-dialog" width="1300px" @open="open" @close="close" :close-on-click-modal="false" :close-on-press-escape="false">
    <div class="app-container">
      <!-- 查询 -->
      <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
        <template slot="search">
          <el-form-item label="统计周期" prop="date">
            <el-date-picker :picker-options="rangeOptions" v-model="startandenddate" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="changedate"></el-date-picker>
          </el-form-item>
          <el-form-item label="" label-width="1px">
            <el-select style="width:180px" v-model="createdepart" placeholder="请选择部门名称" filterable collapse-tags clearable multiple @change="doQueryConcatCreateDepart">
              <el-option v-for="item in codeModel.deptCommonCodeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
          <el-form-item label="" label-width="1px">
            <el-select v-model="projectlevel" multiple collapse-tags placeholder="请选择项目级别" style="width:120px" @change="doQueryConcatProjectLevel">
              <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code"> </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" label-width="1px">
              <el-input v-model="queryParam.qry_projectmanager" style="width:120px" placeholder="工号或姓名" @keyup.enter.native="doQuery"> </el-input>
          </el-form-item>
          <el-form-item label="" label-width="1px">
            <el-input v-model="queryParam.qry_projectname" placeholder="项目名称或编号" @keyup.enter.native="doQuery"></el-input>
          </el-form-item>
        </template>
      </tl-list-search>
      <!-- 工具栏 -->
      <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0" :isDisplayAdd="false" :isDisplayDeleteBatch="false">
        <template slot="left-btn"> </template>
      </tl-list-toolbar>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" resizable-key="tableHeight" :height="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @row-click="doRowClick" @selection-change="doSelectChange" @sort-change="doSortChange" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="dispdeptcommoncode" label="省区" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectname" label="项目名称" min-width="200px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectcode" label="项目编号" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectmanager" label="项目经理" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="四张表获取情况" width="80px" header-align="center" align="center" :show-overflow-tooltip="true">
          <el-table-column prop="taskst1" label="上次评标专家名单" width="150px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst2" label="标杆对标" width="80px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst3" label="细项得分" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst4" label="专家库名单" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        </el-table-column>
        <el-table-column label="第一阶段自评" width="80px" header-align="center" align="center" :show-overflow-tooltip="true">
          <el-table-column prop="ziping1" label="已开展自评" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="baifang1" label="有效专家拜访记录（条）" width="180px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="tifen1" label="差距项均制定提分计划" width="200px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dacheng1" label="差距追赶目标达成率" width="200px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst5" label="已识别客户决策链" width="200px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        </el-table-column>
        <el-table-column label="标前引导" width="80px" header-align="center" align="center" :show-overflow-tooltip="true">
          <el-table-column prop="taskst6" label="履约评价/运行绩效" width="150px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst7" label="检测标准" width="80px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst8" label="技术规范" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst9" label="评分细则" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst10" label="专用资质业绩要求" width="140px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst11" label="分标分包限价" width="120px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst12" label="物资需求上报" width="120px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        </el-table-column>
        <el-table-column prop="taskst13" label="加入DMD" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="taskst14" label="项目审查会结果符合预期" width="200px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="bidbegindate" label="挂网日期" width="100px" align="center" header-align="center" :show-overflow-tooltip="true" :formatter="dateFormat"></el-table-column>
        <el-table-column prop="bidenddate" label="开标日期" width="100px" align="center" header-align="center" :show-overflow-tooltip="true" :formatter="dateFormat"></el-table-column>
        <el-table-column label="第二阶段自评" width="80px" header-align="center" align="center" :show-overflow-tooltip="true">
          <el-table-column prop="ziping2" label="已开展自评" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="baifang2" label="有效专家拜访记录（条）" width="180px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="tifen2" label="差距项均制定提分计划" width="200px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dacheng2" label="差距追赶目标达成率" width="200px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        </el-table-column>
        <el-table-column label="专家客户拜访" width="80px" header-align="center" align="center" :show-overflow-tooltip="true">
          <el-table-column prop="taskst15" label="业务部门主任" width="120px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst16" label="业主代表" width="80px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst17" label="评标组长" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst18" label="本次评标专家" width="120px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="taskst19" label="定标会决策客户" width="140px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        </el-table-column>
        <el-table-column prop="dispprojectresult" label="中标结果" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="resulttime" label="中标结果公示日期" width="150px" header-align="center" align="center" :show-overflow-tooltip="true" :formatter="dateFormat"></el-table-column>
        <el-table-column label="第三阶段自评" width="80px" header-align="center" align="center" :show-overflow-tooltip="true">
          <el-table-column prop="dispthisbidlist" label="本次评标专家名单" width="160px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dispbidmark" label="标杆对标" width="80px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dispsmallbidscore" label="细项得分" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dispexpertlist" label="专家库名单" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        </el-table-column>
        <el-table-column prop="supervisecount" label="项目累计被督办次数" width="160px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="taskratio" label="整体任务完成率" width="140px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="signinfo" label="项目问题" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectstate" label="项目状态" width="100px" header-align="center" align="center" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
    <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { validateNull } from '@tapui/utils/validate'
import { exportExcelAxio } from '@tapui/api/office'
import { formatDate } from '@tapui/utils/date'
import { filterObjectNull, rmbFormat } from '@tapui/utils/util'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
const baseUrl = process.env.BASE_API
export default {
  name: 'fourPageSummary',
  mixins: [mixin_list],
  components: {},
  data() {
    return {
      description: '销售项目信息报表',
      urlPrefix: '/mpm/project/',
      url: {
        list: '/mpm/project/queryFourPageForm',
        exportExcel: '/mpm/project/fourPageExportExcel',
        queryCodeList: '/mpm/pMOStandardizationRecord/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'pro.projectlevel',
        sord: 'asc'
      },
      startandenddate: [],
      createdepart: [],
      projectlevel: [],
      title: '项目报表统计',
      visible: false,
      isQueryOnCreated: false,
      tableHeight: '450px',
      rangeOptions: {
        disabledDate: (time) => {
          let now = new Date()
          now.setHours(23, 59, 59)
          return time.getTime() > now.getTime()
        }
      }
    }
  },
  methods: {
    open() {
      this.$nextTick(() => {
        this.projectlevel.push('0')
        this.doQueryConcatProjectLevel(this.projectlevel)
        this.loadData()
      })
    },
    close() {
      this.startandenddate = []
      this.createdepart = []
      this.projectlevel = []
      this.queryParam = {}
      this.visible = false
    },
    changedate(data) {
      if (validateNull(data)) {
        this.queryParam.startdate = null
        this.queryParam.enddate = null
      } else {
        this.queryParam.startdate = data[0]
        this.queryParam.enddate = data[1]
      }
    },
    // 部门名称多选框
    doQueryConcatCreateDepart(data) {
      if (data.length > 0) {
        this.queryParam.qry_deptcommoncode = data
          .map((item) => {
            return "'" + item + "'"
          })
          .join(',')
      } else {
        this.queryParam.qry_deptcommoncode = null
      }
    },
    // 项目级别多选框
    doQueryConcatProjectLevel(data) {
      if (data.length > 0) {
        this.queryParam.qry_projectlevel = data
          .map((item) => {
            return "'" + item + "'"
          })
          .join(',')
      } else {
        this.queryParam.qry_projectlevel = null
      }
    },
    getQueryParams() {
      let param = {}
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      Object.assign(param, this.queryParam, this.sorterInfo, this.filtersInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      return filterObjectNull(param)
    },
    afterLoadData() {
      this.$refs.mainTable.doLayout()
    },
    /** 导出Excel*/
    doExportExcel() {
      if (!this.beforeExportData()) return
      let cols = []
      // 递归获取el-table的column
      this.dfsColumn(this.$refs.mainTable, cols)
      let url = baseUrl + `${this.url.exportExcel}`
      let data = {}
      Object.assign(data, this.getQueryParams(), { cols: cols.join(',') })
      // 去除分页参数
      delete data.currentPage
      delete data.pageSize
      exportExcelAxio({ url: url, data: data })
        .then((res) => {
          var reader = new FileReader()
          reader.readAsText(res.data, 'utf-8')
          reader.onload = () => {
            try {
              var info = JSON.parse(reader.result)
              this.$tap.alert(info.message)
            } catch (e) {
              var isTaskExport = res.headers.istaskexport
              if (isTaskExport === '1') {
                this.$tap.alert('系统正在导出，请到excel导出任务页面下载')
              } else {
                var blob = new Blob([res.data], { type: 'application/octet-stream;charset=utf-8' })
                var filename = decodeURI(res.headers['filename'])
                if (typeof filename === 'undefined') {
                  filename = '导出数据.xlsx'
                }
                var tempObjectUrl = window.URL.createObjectURL(blob)
                var aLink = document.createElement('a')
                aLink.style.display = 'none'
                aLink.download = filename
                aLink.href = tempObjectUrl
                document.body.appendChild(aLink)
                aLink.click()
                document.body.removeChild(aLink)
                window.URL.revokeObjectURL(tempObjectUrl)
                this.afterExportData()
              }
            }
          }
        })
        .catch((error) => {
          this.$tap.alert(error, 'warning')
        })
    },
    // 递归获取el-table的各个列名称
    dfsColumn(mainTable, cols) {
      if (mainTable.$options._componentTag === 'el-table-column') {
        if (mainTable.$options.propsData.prop) {
          cols.push(mainTable.$options.propsData.prop + ';' + mainTable.$options.propsData.label)
        }
      }
      if (validateNull(mainTable.$children)) {
        return
      } else {
        for (let i = 0; i < mainTable.$children.length; i++) {
          this.dfsColumn(mainTable.$children[i], cols)
        }
      }
    }
  }
}
</script>

<style scoped></style>
